package com.xhl.common.JdkProcy;

import com.xhl.common.util.MakeRSAUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理模式之 jdk动态代理
 * jdk 动态代理模板之 InvocationHandler
 * @Author CazCen
 * @Date 2021/12/2 11:43
 */

public class ServiceInvocationHandler implements InvocationHandler {

    private static final Logger logger = LoggerFactory.getLogger(ServiceInvocationHandler.class);

    /**
     * 目标类对象
     */
    private Object target;

    public ServiceInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        logger.info("前面进行增强.....");
        Object obj = method.invoke(target);
        logger.info("后面进行增强.....");
        return obj;
    }
}
